import { ipcMain, IpcMainInvokeEvent } from 'electron'
import Ffmpeg from './ffmpeg'
import { selectDirectory } from './directory'
import { compressOptions } from '../renderer/src/type'

let ffmpeg = null as Ffmpeg | null
// 压缩视频
ipcMain.handle('compress', async (_event: IpcMainInvokeEvent, options: compressOptions) => {
  const compress = new Ffmpeg(_event, options)
  ffmpeg = compress
  compress.run()
})

// 选择目录
ipcMain.handle('selectDirectory', async () => {
  return selectDirectory()
})

ipcMain.on('stop', () => {
  ffmpeg?.stop()
})
